package com.cw.war.ui
{
	import com.cw.war.model.core.DebugModel;
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.MovieClip;
	
	import net.libra.core.ModelEvent;
	
	import org.aswing.FlowLayout;
	import org.aswing.JFrame;
	import org.aswing.JScrollPane;
	import org.aswing.JTextArea;
	import org.aswing.JWindow;
	import org.aswing.border.LineBorder;

	/**
	 * 
	 * @author elvisjiang
	 * @data 2012-6-13
	 */	
	public class DeBugBox extends JFrame
	{
		public function DeBugBox(root:DisplayObjectContainer)
		{
			
			super(root,"debug工具");
			this.setSizeWH(500,400);
			this.setLocationXY(500,400);
			this.setBorder(new LineBorder());
//			this.getContentPane().setLayout(new FlowLayout());
			initDisplay();
		}
		private var _textArea:JTextArea;
		private function initDisplay():void
		{
			_textArea = new JTextArea();
			this.mouseChildren = true;
			this.mouseEnabled = true;
	 		_textArea.setEditable(false);
			_textArea.setWordWrap(true);
			_textArea.getTextField().scrollV = _textArea.getTextField().maxScrollV;
			var  ja:JScrollPane = new JScrollPane(_textArea,JScrollPane.SCROLLBAR_ALWAYS,JScrollPane.SCROLLBAR_NEVER);
			this.getContentPane().append(ja);
			ja.setComBoundsXYWH(0,0,this.width,this.height);
		}
		private var _model:DebugModel;
		public function setModel(b:DebugModel):void
		{
			if(_model)
			{
				finalizeModel();
			}
			this._model = b;
			this._model.addEventListener(ModelEvent.UPDATE_FINISH,render);
			render();
		}
		
		private var str:String;
		protected function render(event:ModelEvent = null):void
		{
			if(_model){
				str = "";
				for(var i:int = 0;i<_model.logStrArray.length;i++)
				{
					str += _model.logStrArray[i] + "\n";
				}
				_textArea.setText(str);
			}
		}
		private function finalizeModel():void
		{
			_model.removeEventListener(ModelEvent.UPDATE_FINISH,render);
			_model = null;
		}
		
		override public function dispose():void
		{
			finalizeModel();
			_textArea = null;
			super.dispose();
		}
	}
}